16. Type and Type Conversion

Type & Type Conversion

Type and Type Conversion

You have seen four data types so far:

  1. int
  2. float
  3. bool
  4. string

You got a quick look at type() from an earlier video, and it can be used to check the data type of any variable you are working with.

>>> print(type(4))
int
>>> print(type(3.7))
float
>>> print(type('this'))
str
>>> print(type(True))
bool

You saw that you can change variable types to perform different operations. For example,

"0" + "5"

provides completely different output than

0 + 5

What do you think the below would provide?

"0" + 5

How about the code here:

0 + "5"

Checking your variable types is really important to assure that you are retrieving the results you want when programming.